﻿using System.Diagnostics;
using System.Windows;
using System.Windows.Controls;

namespace TotalApplication.AngelSix
{
    /// <summary>
    /// TextEntryControl.xaml 的交互逻辑
    /// </summary>
    public partial class TextEntryControl : UserControl
    {

        #region DependencyProperties

        public GridLength LabelWidth
        {
            get { return (GridLength)GetValue(LabelWidthProperty); }
            set { SetValue(LabelWidthProperty, value); }
        }


        public static readonly DependencyProperty LabelWidthProperty =
            DependencyProperty.Register("LabelWidth", typeof(GridLength), typeof(TextEntryControl), new PropertyMetadata(GridLength.Auto,OnLabelWidthChanged));

        #endregion

        #region Constructor

        public TextEntryControl()
        {
            InitializeComponent();
        }
        #endregion

        #region Dependency Invoke Methods

        public static void OnLabelWidthChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            try
            {
                ((TextEntryControl)d).labelColumnDefination.Width = (GridLength)(e.NewValue);
            }
            catch
            {
                // Make developer aware of the potential issue
                Debugger.Break();

                ((TextEntryControl)d).LabelWidth = GridLength.Auto;
            }
        }

        #endregion
    }
}
